package com.kingint.web.admin.serve.controller;


import com.kingint.mbg.dto.BackQueryParam;
import com.kingint.mbg.dto.rushHouse.RushHouseBackParam;
import com.kingint.mbg.dto.rushHouse.RushHouseFrontParam;
import com.kingint.mbg.group.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.admin.serve.service.SerRushHouseService;
import com.kingint.mbg.ser.entity.SerRushHouse;


/**
 * @描述：发布赶房表控制类
 * @作者: wxh
 * @日期: 2021-01-07
 */
@RestController
@RequestMapping("/serRushHouse")
@Api(value = "SerRushHouseController", description = "发布赶房表")
@CrossOrigin
public class SerRushHouseController {

    @Autowired
    public SerRushHouseService serRushHouseService;


    @ApiOperation(value = "添加发布赶房表")
    @PostMapping("/create")
//    @PreAuthorize("hasAuthority('serRushHouse:create')")
    public Object create(@Validated(Insert.class) @RequestBody RushHouseFrontParam rushHouseFrontParam) {
        int i = serRushHouseService.insertRushHouseInfo(rushHouseFrontParam);
        if (i > 0) {
            return K.ok().data(i);
        } else {
            return K.error();
        }
    }


    @ApiOperation(value = "删除发布赶房表")
    @DeleteMapping("/delete/{id}")
//    @PreAuthorize("hasAuthority('serRushHouse:delete')")
    public Object delete(@PathVariable("id") Integer id) {
        int i = serRushHouseService.deleteRushHouseInfo(id);
        if (i > 0) {
            return K.ok().data(i);
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "根据发布赶房表名称分页获取发布赶房表列表")
    @GetMapping("/list")
//    @PreAuthorize("hasAuthority('serRushHouse:list')")
    public Object getList(BackQueryParam queryParam,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        IPage<RushHouseBackParam> houseList = serRushHouseService.getRushHouseList(queryParam, pageNum, pageSize);
        return K.ok().data(houseList);
    }

    @ApiOperation(value = "根据编号查询发布赶房表信息")
    @GetMapping("/{id}")
//    @PreAuthorize("hasAuthority('serRushHouse:get')")
    public Object getItem(@PathVariable("id") Integer id) {
        SerRushHouse serRushHouse = serRushHouseService.getRushHouseInfo(id);
        return K.ok().data(serRushHouse);
    }

    @ApiOperation(value = "验收人验收赶房工单(1，验收，0，拒绝）,id为workId")
    @GetMapping("/completeRushHouseInfo")
    public Object completeRushHouseInfo(@RequestParam(value = "status", defaultValue = "0") Integer status,
                                        @RequestParam("workId") Integer id) {
        int i = serRushHouseService.completeRushHouseInfo(status, id);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }
}